package com.android.monee.binding.adapter;

import com.android.monee.binding.Field;
import com.android.monee.binding.observable.Observable;
import com.android.monee.binding.observable.ObservableImpl;
import com.android.monee.binding.observer.Observer;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.TextView;

public abstract class AbstractBindableObservableAdapter<S extends TextView> implements TextWatcher,
		Observable<S> {

	protected Observable<S> observableDelegate;

	public AbstractBindableObservableAdapter(S observedData) {
		this.observableDelegate = new ObservableImpl<S>(observedData);
		observedData.addTextChangedListener(this);
	}

	@Override
	public void afterTextChanged(Editable s) {}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {}

	@Override
	public abstract void onTextChanged(CharSequence s, int start, int before, int count);

	public <T, V> void addObserver(Observer<S, T, V> o) {
		observableDelegate.addObserver(o);
	}

	public <T, V> void deleteObserver(Observer<S, T, V> o) {
		observableDelegate.deleteObserver(o);
	}

	public <T, V> void notify(Class<? extends Field> fieldClass) {
		observableDelegate.notify(fieldClass);
	}

	public S getObservedData() {
		return observableDelegate.getObservedData();
	}

}
